$(function(){
    //渲染最新
    $.ajax({
        url:'http://localhost:3000/report/new',
        type:'get',
        success(res){
            $(res).each(function(i,item){
                let str=`
                <div class="box">
                <img src="${item.img}" alt="" class="pic">
                <div class="textBox">
                    <p>${item.text}</p>
                    <div class="susu">
                        <div class="left"><img src="./img/tx.jpg" alt="" class="touxiang"><span class="span1">${item.uName}</span> <span>${item.endTime}</span></div>
                        <div class="zan">
                            <span><img src="./img/xinRedo.png" alt=""> 3 </span>
                            <span><img src="./img/reply.png" alt=""> 5 </span>
                        </div>
                    </div>
                </div>
            </div>
                `
                $('.cat1').prepend(str);
            })
        }
    })
    //渲染最热
    $.ajax({
        url:'http://localhost:3000/report/hot',
        type:'get',
        success(res){
            $(res).each(function(i,item){
                let str=`
                <div class="box">
                <img src="${item.img}" alt="" class="pic">
                <div class="textBox">
                    <p>${item.text}</p>
                    <div class="susu">
                        <div class="left"><img src="./img/tx.jpg" alt="" class="touxiang"><span class="span1">${item.uName}</span> <span>${item.endTime}</span></div>
                        <div class="zan">
                            <span><img src="./img/xinRedo.png" alt=""> 3 </span>
                            <span><img src="./img/reply.png" alt=""> 5 </span>
                        </div>
                    </div>
                </div>
            </div>
                `
                $('.cat2').append(str);
            })
        }
    })
    //点击加载更多
    $('.load').on('click',function(){
        // $('.content').css('height','auto')
        $(this).siblings('.cnt').css('height','auto')
        $(this).text('')
    })
    //点击切换
    $('.tabBtn').on('click',function(){
        console.log($(this).index());
        $('.big').eq($(this).index()).stop().fadeIn().siblings('.big').stop().fadeOut();
    })
        //回到顶部
        $('.back').on('click',function(){
            $('body,html').stop().animate({
                scrollTop: 0
            })
    
        })
        //滚动到某个位置 回到顶部按钮显示或隐藏
        $(document).on('scroll',function(){
            if($(this).scrollTop()>600){
                $('.back').fadeIn();
            }else{
                $('.back').fadeOut();
            }
        })
})
